package rssmanager.service;
 
import java.sql.*;

public final class DBConnect{	
	//Static instance of connection, only one will ever exist
	private static Connection connection = null;		
	//Returns single instance of connection
	public static Connection getConnection(){		
		//If instance has not been created yet, create it
		if(DBConnect.connection == null){
			initConnection();
		}
		return DBConnect.connection;
	}	
	//Gets JDBC connection instance
	private static void initConnection(){			
		try{		
			Class.forName("com.mysql.jdbc.Driver");		
			
			String url = "jdbc:mysql://localhost/rssmanager";
			String user = "root";
			String pw = "";
			DBConnect.connection =
                         DriverManager.getConnection(url, user, pw);		
		}
		catch (ClassNotFoundException e){		
			System.out.println(e.getMessage());
			System.exit(0);
		}
		catch (SQLException e){			
			System.out.println(e.getMessage());
			System.exit(0);
		}
		catch (Exception e){		
		}		
	}
}